package com.example.demo.myqueue;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import lombok.Data;

@Data
public class Message implements Delayed {

    private Integer id;

    private String topic;

    private String comment;

    private long excuteTime;

    public Message(Integer id, String topic, String comment, long excuteTime) {
        this.id = id;
        this.topic = topic;
        this.comment = comment;
        this.excuteTime = System.currentTimeMillis() + excuteTime;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return excuteTime - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        Message msg = (Message) o;
        return this.excuteTime - msg.getExcuteTime() > 0 ? 1 : -1;
    }
}
